package cn.yunhe.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import cn.yunhe.dao.DaoFactory;
import cn.yunhe.dao.IAdminDao;
import cn.yunhe.entity.Admin;

public class AdminDaoImpl implements IAdminDao {
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;

	public Admin adminLogin(String name, String pwd) {
		Admin admin = null;
		try {
			conn = DaoFactory.getConn();
			String sql = "select * from tb_admin where admin_name =? and admin_pwd=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, name);
			pstmt.setString(2, pwd);

			rs = pstmt.executeQuery();

			if (rs.next()) {
				admin = new Admin(rs.getInt("admin_id"),
						rs.getString("admin_name"), rs.getString("admin_pwd"),
						rs.getInt("admin_flag"));

			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DaoFactory.closeAll(conn, pstmt, rs);
		}

		return admin;
	}

}
